<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加页面</title>
    <script src="/mvc/js/vue.min.js"></script>
    <script src="/mvc/js/axios.min.js"></script>
</head>
<body>

<div id="app">

    <form>
        姓名:<input type="text" v-model="stu.name"> <br>
        年龄:<input type="text" v-model="stu.age"> <br>
        分数:<input type="text"   v-model="stu.score"> <br>
        描述:<input type="text" v-model="stu.info"> <br>
        <input type="button" @click="submitStu" value="添加">
    </form>

</div>
<script>

    let app = new Vue({
        el:"#app",
        data:{
            stu:{}
        },
        /**
         *  axios里面:
         *   params :  提交数据 无论是get/post 数据提交都是get提交 数据都是拼接在 url上面
         *
         *   服务器获取:
         *     req.getParameter("")
         *     request.getParameterMap()
         *
         *   data    提交的数据是json对象
         *      req.getInputStream()  拿到流,把流转成字符串,把字符串转成对象
         */
        methods:{
            submitStu(){
                console.log(this.stu);
                axios({
                    type:"GET",
                    url:"http://localhost:8080/mvc/addStu",
                    params:this.stu
                }).then(resp=>{
                    console.log(resp);
                    console.log(resp.data);
                    if (resp.data.code == 100000){
                        alert(resp.data.msg);
                        //页面跳转
                        location.href = "stus.html";
                    }
                })
            }
        }
    })

</script>

</body>
</html>